import 'package:synchronous_data/synchronous_data.dart';

class SyncModel extends SynchronousData {
  double? score;
  int? age;
  String? name;
  bool? isBoy;
  Map? info;
  List<ObjectModel>? children;
  ObjectModel? object;

  SyncModel(String uuid, {this.score, this.age, this.name, this.isBoy, this.info, this.children, this.object}) : super(uuid) {
    synchronousData(uuid);
  }

  @override
  Future synchronousData(String uuid, {Map<String, dynamic>? dataMap}) {
    return super.synchronousData(uuid, dataMap: toJson());
  }

  @override
  Map<String, dynamic> toJson() {
    return <String, dynamic>{
      "score": score,
      "age": age,
      "name": name,
      "isBoy": isBoy,
      "info": info,
      "children": children?.map((e) => e.toJson()).toList(),
      "object": object?.toJson(),
    };
  }

  @override
  ArchiveAbleObject toObject(Map<String, dynamic> json) {
    score = json["score"];
    age = json["age"];
    name = json["name"];
    isBoy = json["isBoy"];
    info = json["info"];
    children = (json["children"] as List?)?.map((e) {
      return ObjectModel().toObject(Map<String, dynamic>.from(e));
    }).toList();
    object = ObjectModel().toObject(Map<String, dynamic>.from(json["object"]));
    return this;
  }
}

class ObjectModel extends ArchiveAbleObject {
  String? name;
  int? age;

  ObjectModel({this.name, this.age}) : super();

  @override
  Map<String, dynamic> toJson() {
    return {"name": name, "age": age};
  }

  @override
  ObjectModel toObject(Map<String, dynamic> json) {
    if (json is Map) {
      name = json["name"];
      age = json["age"];
    }
    return this;
  }
}
